﻿// ConfigDlg.cpp: 实现文件
//

#include "stdafx.h"
#include "Clicker.h"
#include "ConfigDlg.h"
#include "afxdialogex.h"


// ConfigDlg 对话框

IMPLEMENT_DYNAMIC(ConfigDlg, CDialogEx)

ConfigDlg::ConfigDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_SPELL_CONFIG, pParent)
{

	dlg_druid_pages.push_back(std::make_shared<Config_DruidDlg>(Balance, L"德鲁伊-平衡"));
	dlg_druid_pages.push_back(std::make_shared<Config_DruidDlg>(Restoration, L"德鲁伊-恢复"));
}

ConfigDlg::~ConfigDlg()
{
}

void ConfigDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_TAB_CLASS_SPEC, tab_class_spec_);
}


BEGIN_MESSAGE_MAP(ConfigDlg, CDialogEx)
	ON_NOTIFY(TCN_SELCHANGE, IDC_TAB_CLASS_SPEC, &ConfigDlg::OnSelchangeTabClassSpec)
END_MESSAGE_MAP()


// ConfigDlg 消息处理程序


BOOL ConfigDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	tab_class_spec_.InsertItem(0, L"通用");
	tab_class_spec_.InsertItem(1, L"德鲁伊-平衡");
	tab_class_spec_.InsertItem(2, L"德鲁伊-恢复");
	dlg_page1.Create(IDD_DIALOG_CONFIG_GENERAL, &tab_class_spec_);
	for (auto& page : dlg_druid_pages)
	{
		page->Create(IDD_DIALOG_CONFIG_DRUID, &tab_class_spec_);
	}
	//设定在Tab内显示的范围
	CRect rc;
	tab_class_spec_.GetClientRect(rc);
	rc.top += 20;
	rc.bottom -= 0;
	rc.left += 0;
	rc.right -= 0;
	dlg_page1.MoveWindow(&rc);
	for (auto& page : dlg_druid_pages)
	{
		page->MoveWindow(&rc);
	}

	vec_dlg.resize(1 + dlg_druid_pages.size());
	vec_dlg[0] = &dlg_page1;
	for (int i = 1; i <= dlg_druid_pages.size(); i++)
	{
		vec_dlg[i] = dlg_druid_pages[i - 1].get();
	}

	vec_dlg[0]->ShowWindow(SW_SHOW);
	for (int i = 1; i < vec_dlg.size(); i++)
	{
		vec_dlg[i]->ShowWindow(SW_HIDE);
	}
	cur_sel_tab = 0;

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void ConfigDlg::OnSelchangeTabClassSpec(NMHDR *pNMHDR, LRESULT *pResult)
{
	// TODO: 在此添加控件通知处理程序代码
	vec_dlg[cur_sel_tab]->ShowWindow(SW_HIDE);
	//得到新的页面索引
	cur_sel_tab = tab_class_spec_.GetCurSel();
	//把新的页面显示出来
	vec_dlg[cur_sel_tab]->ShowWindow(SW_SHOW);

	*pResult = 0;
}
